package com.qp.projectname.dao.abstractdao;


import com.qp.smsmarketing.entity.Grupo;
import java.util.Iterator;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author waldenilson
 */
public class Hib {

    //private static SessionFactory sf;
    private static EntityManagerFactory factory = null;
    //private EntityManager entityManager;
    private Hib()
    {

        
        factory = Persistence.createEntityManagerFactory("smsm");
//        AnnotationConfiguration a = new AnnotationConfiguration()
//                .setProperty("hibernate.connection.driver_class","org.apache.derby.jdbc.EmbeddedDriver")
//                .setProperty("hibernate.connection.url", "jdbc:derby:contatos;create=true")
//                .setProperty("hibernate.default_schema","contatos")
//                .setProperty("hibernate.cache.provider_class","org.hibernate.cache.NoCacheProvider")
//                .setProperty("hibernate.connection.username", "root")
//                .setProperty("hibernate.connection.password", "wal123")
//                .setProperty("hibernate.hbm2dll.auto","update")
//                .setProperty("hibernate.show_sql", "true")
//                .setProperty("hibernate.format_sql","true")
//                .addAnnotatedClass(Grupo.class)
//                .addAnnotatedClass(Contato.class)
//                .addAnnotatedClass(GrupoContato.class)
//                .addAnnotatedClass(Role.class)
//                .addAnnotatedClass(Usuario.class)
//                .addAnnotatedClass(Mensagem.class)
//                .addAnnotatedClass(MensagemContato.class)
//                .addAnnotatedClass(TipoMsg.class)
//                .addAnnotatedClass(MensagemTipoMsg.class);
//
//        sf = a.buildSessionFactory();
    }

    public static EntityManager getSessionFactory()
    {
        if(factory == null)
            new Hib();
        return factory.createEntityManager();
    }

    public Iterator initDB()
    {
        try
        {
            return null;
    //        return s.createQuery("FROM MensagemTipoMsg").iterate();
            
        }
        catch(Exception e)
        {
            System.out.println(""+e);

            return null;
        }
    } 
}
